#include<iostream>
#include <vector>
#include <math.h>
using namespace std;


vector<int> getGoodIndices(vector<vector<int>>& variables, int target)
{
    vector<int> goodIndices(0);
    for(int i=0;i<variables.size();i++){
        long a = pow(variables[i][0],variables[i][1]);
        long b = pow(a%10,variables[i][2]);
        long c = b % variables[i][3];
        if(c==target)
        {
            goodIndices.push_back(i);
        }
    }
    // cout<<"good indices are:"<<endl;
    // for(int i=0;i<goodIndices.size();i++){
    //     cout<<goodIndices[i]<<" ";
    // }
    return goodIndices;
}


int main(){
    vector<vector<int>> variables(1, std::vector<int>(4));
    int target;
    cout<<"enter two martix:"<<endl;
    for(int i=0;i<1;i++)
    {
        for(int j=0;j<4;j++)
        {
            cin>>variables[i][j];
        }
    }
    cout<<"enter target:"<<endl;
    cin>>target;
    cout<<"martix is:"<<endl;
    for(int i=0;i<1;i++)
    {
        for(int j=0;j<4;j++)
        {
            cout<<variables[i][j]<<" ";
        }
        cout<<endl;
    }
    getGoodIndices(variables, target);
    return 0;
}